<?php

namespace App\Admin\Controllers\Sentence;

use App\Admin\Repositories\Sentence\OftenExpression;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class OftenExpressionController extends AdminController
{
    protected $title = '常用表达法';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new OftenExpression(['category.parent', 'click_learn']), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('category.name', '单元');
            $grid->column('click_learn.content', '文本');
            $grid->column('click_learn.translation', '翻译');
            $grid->column('click_learn.audio_url', '音频');
            $grid->column('sort', '排序')->sortable();

            $grid->disableCreateButton();
            $grid->disableActions();
            $grid->disableBatchDelete();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->panel();
                $filter->equal('id')->width(2);
                $filter->like('category.parent.name', '年级')->select(OftenExpression::categoryList())->width(2);
                $filter->like('click_learn.content', '文本')->width(2);
                $filter->like('click_learn.translation', '翻译')->width(2);
            });

            $grid->selector(function (Grid\Tools\Selector $selector) {
                $selector->select('category.parent.id', '年级', OftenExpression::categoryList());
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new OftenExpression(), function (Show $show) {
            $show->field('id');
            $show->field('category_id');
            $show->field('click_learn_id');
            $show->field('sort');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new OftenExpression(), function (Form $form) {
            $form->display('id');
            $form->text('category_id');
            $form->text('click_learn_id');
            $form->text('sort');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
